14. Car Class File
Nd113 C2 L3 17 L Car Class File V2
Notes on the car.py
file
class Car(object):
this looks a bit like a function declaration, but the word class let’s Python know that the code that follows should describe the state and functionality of a car object.Objects are always capitalized, like Car.
The
__init__
function is responsible for creating space in memory to make a specific car object like carla, and it is where initial state variable are set with statements likeself.state = [position, velocity]
The
move()
function uses a constant velocity model to move the car in the direction of its velocity, vx, and vy, and it updates the state.The
turn_left()
function rotates the velocity values to the left 90 degrees, and it updates the state!